package pl.put.to.classification.verification.error;

import pl.put.to.classification.data.DataInstance;
import pl.put.to.classification.data.DataSet;
import pl.put.to.classification.utils.MatrixUtils;
import Jama.Matrix;

public abstract class AErrorVeryficator implements IErrorVeryficator {
	public double countError(DataSet data, Matrix weights) {
		double error = 0;

		for (DataInstance instance : data.getInstances()) {
			double y = DataSet.determineY(instance.getClassVariableValue());
			Matrix x = MatrixUtils.convertToVector(instance.getVariableValues());

			double margin = MatrixUtils.convertToScalar(weights.transpose().times(x.transpose()).times(y));
			
			error = modifyError(error, margin);
		}

		return error;
	}

	protected abstract double modifyError(double currentError, double margin);
}
